package com.weipai.demo.util;


import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * @author songmengqiang
 * @create 2018-08-29 11:08
 **/

public class User implements Serializable {

    public static final String HEADER_TYPE_KEY = "user-type";

    public static final String KEY = "loginuser";

    public static final int EMPLOYEE = 0;//员工,管理员
    public static final int CUSTOMER = 1;//商城普通用户

    public User(int type, Object user) {
        this.type = type;
        this.user = user;
    }

    private int type;

    private Object user;


    private Map<String, Object> extData = new HashMap<>();

    public <T> T getUser() {
        return (T) user;
    }

    public void put(String key, Object value) {
        extData.put(key, value);
    }

    public <T> T get(String key) {
        return (T) extData.get(key);
    }

    public boolean isEmployee() {
        return type == EMPLOYEE;
    }

    public boolean isCustomer() {
        return type == CUSTOMER;
    }

    @Override
    public String toString() {
        return "User{" +
                "type=" + type +
                ", user=" + user +
                ", extData=" + extData +
                '}';
    }
}
